package com.wex.app.tools;

import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;

public class UiActions extends EventHandler {

    final private int EVENT_ACTION = 1;

    public UiActions(EventRunner eventRunner) {
        super(eventRunner);
    }

    @Override
    protected void processEvent(InnerEvent event) {
        switch (event.eventId) {
            case EVENT_ACTION:
                if (event.object instanceof Runnable)
                {
                    Runnable run = (Runnable)(event.object);
                    run.run();
                }
                break;
            default:
                break;
        }
    }

    //传递需要在ui线程下的操作内容
    public void action(Runnable r) {
        InnerEvent innerEvent = InnerEvent.get(EVENT_ACTION, r);
        sendEvent(innerEvent, 0, Priority.HIGH);
    }
}
